#include <string>
#include "String.h"
void Print(const std::string &s)
{
    for (auto ch : s)
    {
        std::cout << ch;
    }
    std::cout << std::endl;
}

void Print(const wxd::string &s)
{
    for (auto ch : s)
    {
        std::cout << ch;
    }
    std::cout << std::endl;
}

void TestStdString01()
{
    std::string s1 = "Hello World";
    // //std::string s2(s1,1);
    // //std::string s2(10,'W');
    // std::string s2("Hello World",5);
    // std::cout <<s2<<std::endl;
    // std::cout<<s2.size()<<std::endl;

    // 遍历1
    for (int i = 0; i < s1.size(); i++)
    {
        std::cout << s1[i];
    }
    std::cout << std::endl;

    // //遍历2
    // std::string::iterator it = s1.begin();
    // while(it != s1.end())
    // {
    //     std::cout<<*it++;
    // }
    // std::cout<<std::endl;

    // 遍历3 -范围for（本质迭代器）
    for (auto &ch : s1)
    {
        std::cout << ch;
    }
    std::cout << std::endl;

    std::string::iterator it = s1.begin();
    while (it != s1.end())
    {
        //*it+=2;
        std::cout << *it;

        it++;
    }
    std::cout << std::endl;
    for (auto &ch : s1)
    {
        std::cout << ch;
    }
    std::cout << std::endl;
    // std::string::reverse_iterator rit = s1.rbegin();
    // while(rit != s1.rend())
    // {
    //     std::cout<<*rit;
    //     rit++;s
    // }
    // std::cout<<std::endl;
    std::cout << s1.max_size() << std::endl;

    s1.push_back('w');
    s1.push_back('w');
    s1.push_back('w');

    s1 += 'x';
    s1 += 'x';
    s1 += 'x';

    s1.append("ddd");

    std::string::iterator it1 = s1.begin();
    s1.insert(it1, 'T');

    s1.erase(0, 1);
    s1.erase(11);
    for (int i = 0; i < s1.size(); i++)
    {
        std::cout << s1[i];
    }
    std::cout << std::endl;
}

void TestStdString02()
{
    // std::string s1 = "test.cpp.zip";
    // size_t pos = s1.rfind('.');
    // std::string s2 = s1.substr(pos);
    // Print(s2);

    std::string s1 = "Never put off what you can do today until tomorrow.";
    size_t found = s1.find_first_not_of("abcd");

    while (found < std::string::npos)
    {
        s1[found] = '*';
        found = s1.find_first_not_of("abcd", found + 1);
    }
    Print(s1);
}

void TestStdString03()
{
    std::string s1;
    getline(std::cin, s1);
    Print(s1);
}
void TestWxdString01()
{
    wxd::string s1;
    Print(s1);
    wxd::string s2 = "Hello WXD";
    s2[0] = 'X';
    Print(s2);

    const wxd::string s3 = "Hello Const";
    // s3[0] = 'X';
    Print(s3);
}
void PrintCS(const wxd::string &s)
{
    std::cout << "capacity:" << s.capacity() << std::endl;
    std::cout << "size:" << s.size() << std::endl;
    std::cout<<"---"<<std::endl;
}

void TestWxdString02()
{
    wxd::string s1;
    PrintCS(s1);

    s1.push_back('W');
    s1.push_back('X');
    s1.push_back('D');
    s1.push_back('D');
    s1.push_back('D');
    s1.push_back('D');
    s1.push_back('D');
    s1.push_back('D');
    s1.push_back('W');
    PrintCS(s1);

    Print(s1);
}

void TestWxdString03()
{
    wxd::string s1 = "WXD";
    // //3 3
    // PrintCS(s1);
    // s1.append("wxdDDDDDDDDDDDDDDDDD");
    // //6 6
    // PrintCS(s1);
    // Print(s1);

    s1 += 'a';
    s1 += "bbb";
    Print(s1);
    wxd::string s2 = "Hello World";
    PrintCS(s2);
    // s2.erase(7);
    // PrintCS(s2);
    s2.insert(0, 'X');
    s2.insert(6, 'X');
    PrintCS(s2);
    s2.insert(s2.size(), 'X');
    PrintCS(s2);
    Print(s2);

    wxd::string s3 = s1;
    // Print(s3);
    // printf("%p\n",s2.c_str());
    // printf("%p\n",s3.c_str());
    s3.insert(0,"XXX");
    Print(s1);
    Print(s3);
    std::cout<<"---"<<std::endl;
    std::cout<<s1.c_str()<<std::endl;
    std::cout<<s3.c_str()<<std::endl;
}

void TestWxdString04()
{
    wxd::string s1 = "Hello World";
    //std::cout<<s1.find('W')<<std::endl;
    //std::cout<<s1.find("orl")<<std::endl;
    wxd::string s2 = s1.substr(6,5);
    Print(s2);
}


void TestWxdString05()
{
    wxd::string s1 = "Hello World";
    wxd::string s2;
    s2 = s1;
    Print(s2);
    printf("%p\n",s1.c_str());
    printf("%p\n",s2.c_str());

    std::cin>>s1;
    wxd::getline(std::cin,s2);
    std::cout<<s1<<std::endl;
    std::cout<<s2<<std::endl;
}

int main()
{
    // TestStdString01();
    // TestStdString02();
    // TestStdString03();
    // TestWxdString01();
    // TestWxdString02();
    //TestWxdString03();
    //TestWxdString04();
    //TestWxdString05();
    return 0;
}